package com.nju.edu.erp.service.promotion;

import com.nju.edu.erp.dao.PromotionDao;
import com.nju.edu.erp.model.po.promotion.PromotionOnePO;
import com.nju.edu.erp.model.po.promotion.PromotionThreePO;
import com.nju.edu.erp.model.po.promotion.PromotionTwoPO;
import com.nju.edu.erp.model.vo.promotion.PromotionVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PromotionServiceImpl implements PromotionService{
    private final PromotionDao promotionDao;
    @Autowired
    public PromotionServiceImpl(PromotionDao promotionDao) {
        this.promotionDao=promotionDao;
    }

    @Override
    public void setStrategy(PromotionVO promotionVO) {
        SetPromotion setPromotion = null;
       Integer type= promotionVO.getType();
       switch (type){
           case 1:
               setPromotion=new SetPromotionOne(promotionDao,promotionVO);break;
           case 2:
               setPromotion=new SetPromotionTwo(promotionDao,promotionVO);break;
           case 3:
               setPromotion=new SetPromotionThree(promotionDao,promotionVO);break;
       }
       setPromotion.setPromotion(promotionVO);

    }

    @Override
    public List<PromotionVO> getPromotion() {
        List<PromotionOnePO> promotionOnePOS=promotionDao.getAllPromotionOne();
        List<PromotionTwoPO> promotionTwoPOS=promotionDao.getAllPromotionTwo();
        List<PromotionThreePO> promotionThreePOS=promotionDao.getAllPromotionThree();
        List<PromotionVO> res=new ArrayList<>();
        for (PromotionOnePO p:promotionOnePOS) {
            PromotionVO promotionVO=new PromotionVO();
            promotionVO.setType(1);
            BeanUtils.copyProperties(p,promotionVO);
            res.add(promotionVO);
        }
        for (PromotionTwoPO p:promotionTwoPOS) {
            PromotionVO promotionVO=new PromotionVO();
            promotionVO.setType(2);
            BeanUtils.copyProperties(p,promotionVO);
            res.add(promotionVO);
        }
        for (PromotionThreePO p:promotionThreePOS) {
            PromotionVO promotionVO=new PromotionVO();
            promotionVO.setType(3);
            BeanUtils.copyProperties(p,promotionVO);
            res.add(promotionVO);
        }
        return res;
    }


}
